import { IPanelItem } from '@ibiz/model-core'
import { IPanelItemController, ScriptFactory } from '@ibiz-template/runtime'

/**
 * 计算注入属性
 * @param model
 * @param controller
 * @returns
 */
export function calcAttrs(model: IPanelItem, controller: IPanelItemController): IParams {
  const attrs: IParams = {}
  model.controlAttributes?.forEach((item) => {
    if (item.attrName && item.attrValue) {
      attrs[item.attrName!] = ScriptFactory.execSingleLine(item.attrValue!, {
        ...controller.panel.getEventArgs(),
        data: controller.data,
      })
    }
  })
  return attrs
}
